package logic

import (
	"context"
	"manuscript-service/modles/mysql"

	"manuscript-service/servicerpc/internal/svc"
	"manuscript-service/servicerpc/servicerpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type ArticleShowLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewArticleShowLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ArticleShowLogic {
	return &ArticleShowLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *ArticleShowLogic) ArticleShow(in *servicerpc.ArticleShowRequest) (*servicerpc.ArticleShowResponse, error) {
	// todo: add your logic here and delete this line

	var article mysql.Article
	if err := article.ArticleShow(mysql.DB, in.ArticleId); err != nil {
		return nil, err
	}

	return &servicerpc.ArticleShowResponse{
		ArticleId: int64(article.ID),
		Title:     article.Title,
		Content:   article.Content,
		Author:    article.Author,
	}, nil
}
